package com.it.system.gatewayservice.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {


    /**
     * 创建redistemplate对象，返回容器
     */

    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory){
        //创建redis模板对象
        RedisTemplate<String,Object> template=new RedisTemplate<String,Object>();
        //设置连接工厂
        template.setConnectionFactory(factory);
        //创建字符串的序列化器
        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        //设置key的序列化器
        template.setKeySerializer(stringRedisSerializer);
        template.setHashKeySerializer(stringRedisSerializer);
        return template;
    }


}
